package cn.codingjc.peekaboo.application.core.sql.process;

import cn.codingjc.peekaboo.application.core.pipeline.BusinessProcess;
import cn.codingjc.peekaboo.application.core.pipeline.ProcessContext;
import cn.codingjc.peekaboo.application.core.sql.build.MySQLDialect;
import cn.codingjc.peekaboo.application.core.sql.build.SqlBuilder;
import cn.codingjc.peekaboo.application.core.sql.param.SqlSchemaParam;
import cn.codingjc.peekaboo.application.util.MessageUtils;
import cn.codingjc.peekaboo.domain.domain.sql.dto.TableSchemaDTO;
import cn.codingjc.peekaboo.domain.domain.sql.vo.SQLGenerateVO;
import cn.codingjc.peekaboo.domain.domain.sys.vo.ResultVO;
import cn.hutool.core.util.ObjectUtil;

/**
 * @date: 2023/5/4
 * @author: Codingjc
 * @className: BuildTableProcess
 **/
public class BuildTableProcess implements BusinessProcess {
    @Override
    public void process(ProcessContext processContext) {
        SqlSchemaParam sqlSchemaParam = (SqlSchemaParam) processContext.getProcessParam();
        TableSchemaDTO tableSchemaDTO = sqlSchemaParam.getTableSchemaDTO();
        SqlBuilder sqlBuilder = new SqlBuilder(new MySQLDialect());
        String createTableSql = sqlBuilder.buildCreateTableSql(tableSchemaDTO);
        ResultVO result = processContext.getResult();
        SQLGenerateVO sqlGenerateVO = new SQLGenerateVO();
        sqlGenerateVO.setCreateSql(createTableSql);
        if (ObjectUtil.isNull(result)) {
            result = ResultVO.ok(MessageUtils.getMessage("generate.success"), sqlGenerateVO);
        }
        processContext.setResult(result);
    }
}
